package Demo01_15;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 14229 on 2020/1/16.
 */
public class Test15 {
    public static void main(String[] args) {

        String str = "<Dog name='小白' color='白色' sons='小黑,小花'/>";
        String[] split = str.replace("<Dog ", "").replace("/>", "").replace("'", "").split(" ");
        Dog d = new Dog();
        Map<String,String> map = new HashMap<>();
        for (String s : split) {
            String[] split1 = s.split("=");
            map.put(split1[0],split1[1]);
        }
        d.setName(map.get("name"));
        d.setColor(map.get("color"));
        String[] sons = map.get("sons").split(",");
        for (String son : sons) {
            d.getSons().add(son);
        }
        System.out.println(d);
    }
}
